/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package regras;

import Interfaces.CheckerRule;

/**
 *
 * @author Tainá, Ana Luiza e Amanda
 */
public class RuleRequiredCharacters02 implements CheckerRule{
    private String password;
    public RuleRequiredCharacters02(String password) {
        this.password = password;
    }
    
    @Override
    public int rule(){
        int total = 0;
        int requiredChar =0;
        int minimumLength = 8;
         
        String senha = " "+password+" ";
         if (password.length()>=8)
             requiredChar++;
         
         if (senha.split("([A-Z])").length - 1 >=1)
             requiredChar++;
         
         if (senha.split("([a-z])").length - 1 >= 1)
             requiredChar++;
         
         if (senha.split("([0-9])").length - 1 >= 1)
             requiredChar++;
         
         char[] pwd = password.replaceAll("\\s+", "").toCharArray(); 
         for (int i=0; i<pwd.length; i++){
             if ((!Character.isDigit(pwd[i]) && !Character.isLetter(pwd[i]) && pwd[i] != '_')){
                 requiredChar++;
                 break;
             }
         }
  
         int minimumRequiredChar; 
         if (password.length()>= minimumLength) 
             minimumRequiredChar = 3;
         else
             minimumRequiredChar = 4;
         
         if (requiredChar > minimumRequiredChar) 
              total += requiredChar * 2; 
         
         return total;
    }
}
